package pingpongdojo.newgame;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.widgets.Shell;

import pingpongdojo.dialog.FormDialog;
import pingpongdojo.model.ModelFactory;
import pingpongdojo.model.UserManager;

public class NewGameDialog extends FormDialog {

	private String gameName;
	private String partnerUsername;

	public static final FormItemKey GAME_NAME_KEY = new FormItemKey("GameName");
	public static final FormItemKey PARTNER_KEY = new FormItemKey("Partner");

	public NewGameDialog(Shell parentShell) {
		super("New game", "Enter game information:", parentShell);

		addFormItem(new TextFieldFormItem(GAME_NAME_KEY, "Game name:"));

		UserManager userManager = ModelFactory.getInstance().getUserManager();

		List<String> usernames = new ArrayList<String>(
				userManager.getUserNames());

		usernames.remove(userManager.getCurrentUser().getUserName());

		addFormItem(new ComboBoxFormItem(PARTNER_KEY, "Select partner:",
				usernames));
	}

	@Override
	protected String getOKButtonTitle() {
		return "Start New Game";
	}

	public String getGameName() {
		return gameName;
	}

	public String getPartnerUsername() {
		return partnerUsername;
	}

	@Override
	protected void okPressed() {
		// Need to copy form fields into variables because the controls will be
		// disposed after this

		this.gameName = getFormItem(GAME_NAME_KEY).getValue();
		this.partnerUsername = getFormItem(PARTNER_KEY).getValue();

		super.okPressed();
	}

}
